﻿@model ManageAccountsViewModel
           
@{
    ViewBag.Title = @Strings.Accounts;
}

<fieldset class="shaded">
    <legend>@Strings.Accounts</legend>
    <div><a href="/Account/Create#accounts">@Strings.Account_Create</a></div>
    @(Html.Grid(Model.Data).Columns(column =>
        {
            column.For(x => Html.DisplayFor(m => x.Email)).Encode(false).Named("Email").SortColumnName("Email");
            column.For(x => x.FirstName);
            column.For(x => x.LastName);
            column.For(x => String.Join(",", x.GetRoles())).Named("Role").Sortable(false);
            column.For(x => x.Activated);
            column.For(x => Html.ActionLink(Strings.Edit, "Edit", new { id = x.UserId }) + " | " +
                            String.Format("<a href='javascript:void(0);' id='{0}' class='deleteLink' title='{1}'>{2}</a>", x.UserId, x.FullName, Strings.Delete))
                            .Encode(false)
                            .Attributes(x => new Dictionary<string, object> { { "nowrap", "nowrap" } });
        }
    ).Sort(Model.GridSortOptions))
    @Html.Pager(Model.PagingInfo)
</fieldset>

@section head {
    <script type="text/javascript">
        $(document).ready(function () {

            $(".deleteLink").click(function () {
                if (confirm("@Html.Raw(Strings.Account_ConfirmDeleteFormatString)".replace("{0}", $(this).attr("title"))) == false)
                    return false;

                $.post("/Account/Delete/", { 'id': $(this).attr("id") }, function (data) {
                    if (data.Success == true) {
                        document.location.reload();
                    }
                    else {
                        alert(data.Message);
                    }
                });
            });
        });        
    </script>
}
